<?php

namespace App\Http\Controllers\Api\V1\Requests;

use App\Models\User;

class BuyGoldCashRequest extends FormRequest
{
	protected User $child;

	public function rules()
	{
		return [
			'beans' => $this->beans(),
            'pay_code' => $this->paycode(false),
		];
	}

	public function beans()
	{
		return [
            'required',
            'integer',
            function ($key, $value, $fail) {
                if ($value <= 0) {
                    return $fail("请输入正确的数量");
                } elseif ($this->user()->gold_beans <= 0) {
                    return $fail("可用金豆不足");
                } elseif ($this->user()->gold_beans < $value) {
                    return $fail("可用金豆不足");
                } else {
                    return true;
                }
            }
        ];
	}
}
